Skip to content

test: Add custom function tests#25480

Merged
czentgr merged 1 commit intomasterfrom
custom_func_native_tests
Oct 3, 2025
Merged

test: Add custom function tests#25480
czentgr merged 1 commit intomasterfrom
custom_func_native_tests

Conversation

@pramodsatya
Copy link
Copy Markdown
Contributor

@pramodsatya pramodsatya commented Jul 2, 2025

Description

Adds e2e tests for Presto C++ custom functions. Testcases borrowed from AbstractTestQueries in presto-tests.

== NO RELEASE NOTE ==

@prestodb-ci prestodb-ci added the from:IBM PR from IBM label Jul 2, 2025
@prestodb-ci prestodb-ci requested review from a team and sh-shamsan and removed request for a team July 2, 2025 22:31
@pramodsatya pramodsatya force-pushed the custom_func_native_tests branch from 8a0fcf9 to e2dc5bc Compare July 2, 2025 22:37

#include "presto_cpp/main/dynamic_registry/DynamicFunctionRegistrar.h"
#include "velox/expression/SimpleFunctionRegistry.h"
#include <iostream>
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This goes to the top of the list.

// (note the extern "C" directive to prevent the compiler from mangling the
// symbol name).

namespace facebook::velox::common::dynamicRegistry {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this namespace? This is an example so the user could choose whatever namespace they have. I would change this away from a velox namespace and not use velox or presto namespace to indicate complete freedom.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree... we could use a namespace that is more representative of the current folder structure.

#include "presto_cpp/main/dynamic_registry/DynamicFunctionRegistrar.h"
#include "velox/expression/SimpleFunctionRegistry.h"
#include <iostream>
// This file defines a mock function that will be dynamically linked and
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't technically a mock function. It is a real function that carries out an addition.

return prestoRoot
.resolve("presto-native-execution")
.resolve("_build")
.resolve("release")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we change this an be able to check if release exists here and if not use debug? That would handle the case if the build type changes that you don't have control over here.

Copy link
Copy Markdown
Contributor

@aditi-pandit aditi-pandit left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @pramodsatya. Have bunch of comments.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There shouldn't be a need to derive this class from one in presto-tests. We can make TestCustomFunctions a presto-native-tests only class. wdyt ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the suggestion, I agree.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function should be a part of presto-native-tests and can be built by default. There isn't a need to put in the dynamic_registrations examples and set PRESTO_ENABLE_EXAMPLES for it. presto-native-execution needn't be changed at all.

Though you would need to create a top-level cpp code folder in presto-native-tests. So something like add them in a presto_cpp/tests/custom_functions folder.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we keep all C++ UDFs used in e2e tests in presto-native-execution/presto_cpp/main/dynamic_registry/examples, similar to how the Java test UDFs are all placed under presto-tests/src/main/java/com/facebook/presto/tests? Keeping them in presto-native-execution would ensure different dynamic libraries like .so and .dylib for Linux/Mac are suitably built during linux-build process in CI. Also the presto-native-tests CI workflow has a dependency on linux-build CI workflow, ensuring the dynamic libraries are built first. Otherwise, we could also leverage the container based testing framework for this? What do you suggest?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agree with @pramodsatya that having the linux-build process in CI as a dependency would build the libraries first. Also, keeping them under examples, for all other test files we come up with, users can take advantage of reading the code to these files if they stumble upon the dynamic registry function docs as well which could be advantageous.

if we were to build these in cpp in presto-native-tests, they will be built in presto-native-tests after the presto-native-execution build occurs in the linux-build workflow.

afaik, that should be fine if we can be sure that these dynamic files will be built before the test is run. @pramodsatya do you know if that can be made to be the case that the new cpp build for would happen before the E2E test run?

the other thing too, fmt::fmt gflags::gflags xsimd, would be dependencies for these libraries to build and we need to ensure that these will be available for the presto-native-tests cpp build.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So Java test udfs are in a testing specific directory... Its better to separate tests from examples. The examples are demo examples that are documentation. You can build the tests in the linux-build workflow if that is more convenient.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pramodsatya @soumiiow : There is value to showing a custom function example that is not in presto-native-execution. Any user is more likely to copy that setup since they will write their functions in new java/cpp modules.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hey @aditi-pandit just to clarify, id make a Makefile, Cmakelists, put src files, etc and essentially build this completely under, say presto/presto-native-tests/presto-cpp/tests/custom_functions is that a correct interpretation of the ask?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes @soumiiow...

The build command for it can be in linux-build workflow if you prefer.

// (note the extern "C" directive to prevent the compiler from mangling the
// symbol name).

namespace facebook::velox::common::dynamicRegistry {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree... we could use a namespace that is more representative of the current folder structure.

} // namespace facebook::velox::common::dynamicRegistry

extern "C" {
// In this case, we assume that facebook::presto::registerPrestoFunction
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't follow this comment... registerPrestoFunction is available if you include the necessary header in this file.

namespace facebook::velox::common::dynamicRegistry {

template <typename T>
struct DynamicFunctionCustomAdd {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This name can be simply CustomAdd

/// Custom aggregate functions are unsupported in Presto C++.
@Override
@Test (enabled = false)
public void testCustomSum() {}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These 2 test functions are not needed at all.

/// Sidecar is needed to support custom functions in Presto C++.
@Override
@Test
public void testCustomAdd()
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As we are adding a new test for dynamic functions, we can add more scalar functions with a variety of simple types, array, map and struct based functions... nested types as well.


public static Path getCustomFunctionsPluginDirectory()
{
Path workingDir = Paths.get(System.getProperty("user.dir")).toAbsolutePath();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This path cannot be set in jvm arguments and its value is fixed, we intend to keep all the C++ UDFs used in e2e tests in presto-native-execution under the path presto_cpp/main/dynamic_registry/examples. Could you please confirm if this needs to be documented?

@soumiiow soumiiow force-pushed the custom_func_native_tests branch from e2dc5bc to ce68951 Compare July 16, 2025 23:38
@mohsaka mohsaka force-pushed the custom_func_native_tests branch 3 times, most recently from 56fee7c to d7df27e Compare August 13, 2025 20:46
@mohsaka mohsaka self-assigned this Aug 22, 2025
@mohsaka mohsaka force-pushed the custom_func_native_tests branch 5 times, most recently from 574bacf to 471ebcc Compare August 28, 2025 03:14
@aditi-pandit
Copy link
Copy Markdown
Contributor

@pramodsatya & @mohsaka : Please can you merge your commits.

@mohsaka mohsaka force-pushed the custom_func_native_tests branch from 28892b2 to d9fcc4c Compare September 23, 2025 00:55
@mohsaka mohsaka force-pushed the custom_func_native_tests branch 8 times, most recently from e2ff78e to ff0d683 Compare September 27, 2025 01:02
Copy link
Copy Markdown
Contributor

@aditi-pandit aditi-pandit left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mohsaka : This code is looking good minus the question about the test.

Comment thread .github/workflows/prestocpp-linux-build-and-unit-test.yml Outdated
private boolean sidecarEnabled;

@BeforeSuite
public void buildNativeLibrary()
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Am still not sure I follow : Why can we not do this in the pipeline ?

@mohsaka mohsaka force-pushed the custom_func_native_tests branch from ff0d683 to 36273b1 Compare September 30, 2025 18:27
@aditi-pandit
Copy link
Copy Markdown
Contributor

@mohsaka : There are velox update files in this PR. Do you need them or this was an accident ? I'll send an Advance Velox PR nonetheless.

@mohsaka
Copy link
Copy Markdown
Contributor

mohsaka commented Sep 30, 2025

@mohsaka : There are velox update files in this PR. Do you need them or this was an accident ? I'll send an Advance Velox PR nonetheless.

Sorry, did not intend to advance velox. Will remove it

@mohsaka mohsaka force-pushed the custom_func_native_tests branch from 36273b1 to 45b9801 Compare September 30, 2025 20:27
aditi-pandit
aditi-pandit previously approved these changes Sep 30, 2025
Copy link
Copy Markdown
Contributor

@aditi-pandit aditi-pandit left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @mohsaka. @czentgr PTAL as well.

@mohsaka mohsaka force-pushed the custom_func_native_tests branch 2 times, most recently from 6633845 to 72b0506 Compare October 1, 2025 17:27
Co-authored-by: Pramod Satya <pramod.satya@ibm.com>
Co-authored-by: soumiiow <soumyaduriseti@gmail.com>
@mohsaka mohsaka force-pushed the custom_func_native_tests branch from 72b0506 to fb09bb5 Compare October 1, 2025 20:54
@mohsaka mohsaka changed the title [native] Add custom function tests test: Add custom function tests Oct 2, 2025
Copy link
Copy Markdown
Contributor

@aditi-pandit aditi-pandit left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @mohsaka

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

from:IBM PR from IBM

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants